{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}

<div class="p-3">
	<form class="layui-form gg-form-bar border-t border-x">
		<div class="layui-input-inline" style="width:150px;">
			<input type="text" name="keywords" placeholder="搜索姓名" class="layui-input" autocomplete="off" />
			
			
		</div>
		<!-- <div class="layui-input-inline" style="width:150px;">
			<input type="text" name="jiaofei_time"   id="laydate_jiaofei_time" autocomplete="off" placeholder="缴费时间" class="layui-input">
		</div> -->
		<div class="layui-input-inline" style="margin-left:20px">
			<input type="text" name="end_time"   id="laydate_end_time" autocomplete="off" placeholder="开始到期时间" class="layui-input">
		</div>
		<div class="layui-input-inline">~</div>
		<div class="layui-input-inline">
			<input type="text" name="end_time2"   id="laydate_end_time2" autocomplete="off" placeholder="结束到期时间" class="layui-input">
		</div>
		<div class="layui-input-inline">
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="searchform">提交搜索</button>
		</div>
	</form>
	<table class="layui-hide" id="student" lay-filter="student"></table>
</div>

<script type="text/html" id="toolbarDemo">
	
	<div class="layui-btn-container">
		
		<span class="layui-btn layui-btn-sm" lay-event="add" data-title="添加学生">+ 添加学生</span>
		<!-- <span class="layui-btn layui-btn-sm" lay-event="sheng" data-title="添加学生">+ 升年级</span>
		<span class="layui-btn layui-btn-sm" lay-event="jiang" data-title="添加学生">- 降年级</span>(升降仅用于测试自动调整年级) -->
	</div>

	
	
	<div class="layui-btn-container">
		
	</div>
</script>
<script type="text/html" id="toolbarDemo2">
	
</script>

<script type="text/html" id="barDemo">
<div class="layui-btn-group"><!-- <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="read">查看</a> --><a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a><a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a></div>
</script>

{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool'];
	function gouguInit() {
		var table = layui.table,tool = layui.tool, form = layui.form;
		layui.pageTable = table.render({
			elem: '#student',
			title: '学生列表',
			toolbar: '#toolbarDemo',
			url: '/admin/student/datalist',
			page: true,
			limit: 20,
			cellMinWidth: 30,
			cols: [
				[
				{
					fixed: 'left',
					field: 'id',
					title: '编号',
					align: 'center',
					width: 80
				},{
					field: 'name',
					title: '学生姓名',
					align: 'center',
					width: 100,
					templet: function (d) {
						if(d.is_new==1){
							//var html = '<i style="color:red">是</i>';
							var html = d.name+'&nbsp;<span class="layui-badge">新生</span>';
						}else{
							var html = d.name;
						}
						
						return html;
					}
				},{
					field: 'nianji',
					title: '年级',
					align: 'center'
				},{
					field: 'banji',
					title: '班级',
					align: 'center',
					width: 50
				},{
					field: 'sex',
					title: '性别',
					align: 'center',
					width: 50,
					templet: function (d) {
						if(d.sex==1){
							var html = '<span style="color: blue">♂</span>';
						}else{
							var html = '<span style="color: pink">♀</span>';
						}
						
						return html;
					}
				}/*,{
					field: 'is_new',
					title: '是否新生',
					align: 'center',
					templet: function (d) {
						if(d.is_new==1){
							
							var html = '<span class="layui-badge">新生</span>';
						}else{
							var html = '<i></i>';
						}
						
						return html;
					}
				}*/,{
					field: 'jiazhang_lianxi',
					title: '家长联系方式',
					align: 'center'
				},{
					field: 'create_time',
					title: '创建时间',
					align: 'center'
				},{
					field: 'create_admin',
					title: '创建人',
					align: 'center'
				},
				{
					fixed: 'right',
					field: '',
					title: '操作',
					toolbar: '#barDemo',
					width: 136,
					align: 'center'
				}				
				]
			]
		});
		//日期选择
		layui.laydate.render({
			elem: '#laydate_jiaofei_time' //指定元素
		});//日期选择
		layui.laydate.render({
			elem: '#laydate_end_time' //指定元素
		});
		layui.laydate.render({
			elem: '#laydate_end_time2' //指定元素
		});
		//监听表头工具栏事件
		table.on('toolbar(student)', function(obj){
			if (obj.event === 'add') {
				tool.side("/admin/student/add");
				return false;
			}
		});

		//监听表格行工具事件
		table.on('tool(student)', function(obj) {
			var data = obj.data;
			if (obj.event === 'read') {
				tool.side('/admin/student/read?id='+obj.data.id);
			}
			else if (obj.event === 'edit') {
				tool.side('/admin/student/edit?id='+obj.data.id);
			}
			else if (obj.event === 'del') {
				layer.confirm('确定要删除该记录吗?', {
					icon: 3,
					title: '提示'
				}, function(index) {
					let callback = function (e) {
						layer.msg(e.msg);
						if (e.code == 0) {
							obj.del();
						}
					}
					tool.delete("/admin/student/del", { id: data.id }, callback);
					layer.close(index);
				});
			}
			return false;
		});

		//监听搜索提交
		form.on('submit(searchform)', function(data) {
			layui.pageTable.reload({
				where: {
					keywords: data.field.keywords,
					jiaofei_time: data.field.jiaofei_time,
					end_time: data.field.end_time,
					end_time2: data.field.end_time2
				},
				page: {
					curr: 1
				}
			});
			return false;
		});
	}
</script>
{/block}
<!-- /脚本 -->